{#
 # ---------------------------------------------------------------------
 #
 # GLPI - Gestionnaire Libre de Parc Informatique
 #
 # http://glpi-project.org
 #
 # @copyright 2015-2025 Teclib' and contributors.
 # @licence   https://www.gnu.org/licenses/gpl-3.0.html
 #
 # ---------------------------------------------------------------------
 #
 # LICENSE
 #
 # This file is part of GLPI.
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation, either version 3 of the License, or
 # (at your option) any later version.
 #
 # This program is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
 #
 # You should have received a copy of the GNU General Public License
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 #
 # ---------------------------------------------------------------------
 #}

{% import "components/alerts_macros.html.twig" as alerts %}
{% import "components/form/fields_macros.html.twig" as fields %}

{% block more_fields %}
    {% if url is defined %}
        {{ fields.htmlField(
            '',
            '<a href="' ~ url|escape ~ '">' ~ url|escape ~ '</a>',
            __('External survey'),
            {
                full_width: true
            }
        ) }}

    {% else %}
        {% if expired %}
            {% set message = __('Satisfaction survey expired.') %}
        {% else %}
            {% set message = __('After 12 hours, you can no longer modify your response.') %}
        {% endif %}
        {{ alerts.alert_info(message) }}
        {% if item.fields['date_answered'] is empty and expired %}
            {{ fields.htmlField(
                '',
                '',
                __('No response given'),
                {
                    full_width: true
                }
            ) }}
        {% else %}
            {{ fields.hiddenField(
                parent_item.getForeignKeyField(),
                parent_item.fields['id'],
                '',
                {
                    'full_width': true,
                }
            ) }}

            {% set select_dom %}
                <select id="satisfaction_data" name="satisfaction">
                    {% for i in range(0, max_rate) %}
                        <option value="{{ i }}" {% if i == item.fields['satisfaction'] %} selected {% endif %}>{{ i }}</option>
                    {% endfor %}
                </select>
                <div class="rateit" id="stars"></div>
            {% endset %}

            {{ fields.htmlField(
                'satisfaction',
                select_dom,
                __('Satisfaction with the resolution of the %s')|format(parent_item.getTypeName(1)),
                {
                    'full_width': true,
                    'input_class': 'col-xxl-7 text-start',
                }
            ) }}

            {{ fields.textareaField(
                'comment',
                item.fields['comment'],
                _n('Comment', 'Comments', get_plural_number()),
                {
                    'full_width': true,
                    'readonly': expired,
                }
            ) }}

            {% if item.fields['date_answered'] > 0 %}

                {{ fields.datetimeField(
                    'date_answered',
                    item.fields['date_answered'],
                    __('Response date to the satisfaction survey.'),
                    {
                        'full_width': true,
                        'readonly' : true
                    }
                ) }}

            {% endif %}

            <script>
                $(function() {
                    $('#stars').rateit({
                        value: {{ item.fields['satisfaction'] }},
                        min: 0,
                        max: {{ max_rate }},
                        step: 1,
                        backingfld: '#satisfaction_data',
                        ispreset: true,
                        resetable: false
                    });
                });
            </script>

            {% if not expired %}
                {{ include('components/form/buttons.html.twig') }}
            {% endif %}
        {% endif %}
    {% endif %}

{% endblock %}
